#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

#define MAXTOKEN 100
#define TOKENLEN 15
#define BUFFER 256

int calc_expr(void);
int calc_nexpr(int left);
int calc_arith(int left);
int calc_elem(int left);
int calc_primitive();


int calc_expr(){
	char c, token[TOKENLEN];
	int ans=1;
	while((c=getchar())==' ')
		;
	ungetc(c, stdin);
	return calc_nexpr(calc_primitive());
}

int calc_nexpr(int left){
	char c = getchar();
	switch(c){
	case '(':
		while((c=getchar()) != ')')
			left = calc_nexpr(left);
		return left;
		break;
	case ')':
	case '\n':
	case EOF:
		return left;
		break;
	case '^':
		return (int)pow((double)left, calc_expr());
		break;
	default:
		ungetc(c, stdin);
		return calc_arith(left);
		break;
	}
}

int calc_arith(int left){
	char c;
	while((c=getchar())==' ')
		;
	switch(c){
	case '*':
		return left * calc_expr();
		break;
	case '/':
		return left / calc_expr();
		break;
	default:
		ungetc(c, stdin);
		return calc_elem(left);
		break;
	}
}

int calc_elem(int left){
	char c;
	while((c=getchar())==' ')
		;
	switch(c){
	case '+':
		return left + calc_expr();
		break;
	case '-':
		return left - calc_expr();
		break;
	default:
		ungetc(c, stdin);
		return calc_primitive();
		break;
	}
}

int calc_primitive(void){
	char c, token[TOKENLEN];
	int i = 0;

	while((c=getchar())==' ')
		;
	ungetc(c, stdin);
	if(c=='(')
		return 1;
	while(isdigit(c=getchar()))
		token[i++] = c;
	token[i] = '\0';
	return atoi(token);
}



	
	